package com.hyg.common.utils.language;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Locale;

public class SPLanguageUtil {

    private static final String SP_NAME = "common_language_setting";
    private static final String TAG_LANGUAGE = "common_language_select";
    private static final String TAG_SYSTEM_LANGUAGE = "common_system_language";

    public static final String SELECT_LANGUAGE = "SELECT_LANGUAGE";
    private static volatile SPLanguageUtil instance;

    private final SharedPreferences mSharedPreferences;

    private Locale systemCurrentLocal = Locale.US;


    public SPLanguageUtil(Context context) {
        mSharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    }


    public void saveLanguageLocal(String local){

    }


    /**
     * @param select 0:简体，1：繁体，2：英语，3：越南文，4：泰文，5：印地文
     */
    public void saveLanguage(int select) {
        SharedPreferences.Editor edit = mSharedPreferences.edit();
        edit.putInt(TAG_LANGUAGE, select);
        edit.apply();
    }

    public int getSelectLanguage() {
        return mSharedPreferences.getInt(TAG_LANGUAGE, -1);
    }

    public Locale getSystemCurrentLocal() {
        return systemCurrentLocal;
    }

    public void setSystemCurrentLocal(Locale local) {
        systemCurrentLocal = local;
    }

    public static SPLanguageUtil getInstance(Context context) {
        if (instance == null) {
            synchronized (SPLanguageUtil.class) {
                if (instance == null) {
                    instance = new SPLanguageUtil(context);
                }
            }
        }
        return instance;
    }
}
